package com.handpay.framework.swiper.landi;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;

import com.handpay.framework.swiper.SwiperModel;
import com.handpay.zztong.hp.utils.BitmapUtil;
import com.landicorp.android.mposcomm.bitmap.JBigUtil;
import com.landicorp.mpos.reader.BasicReaderListeners.PrintListener;
import com.landicorp.mpos.reader.model.MPosPrintElecSignCache;
import com.landicorp.mpos.reader.model.MPosPrintLine;
import com.landicorp.mpos.reader.model.MPosPrintLine.AlignPosition;
import com.landicorp.mpos.reader.model.MPosPrintLine.Font;
import com.landicorp.mpos.reader.model.MPosPrintTextLine;

/**
 * 联迪M36刷卡器封装
 * @author zzmiao
 *
 */
public class LandiSwiperM36 extends LandiSwiperBT {
	
	public LandiSwiperM36(Context context, String address) {
		super(context, address);
	}

	@Override
	public boolean printString(String data) {
		if (null == reader || null == data) {
			return false;
		}
		ArrayList<MPosPrintLine> printData = new ArrayList<MPosPrintLine>();
		MPosPrintTextLine content = new MPosPrintTextLine(AlignPosition.LEFT, Font.ZOME2X2, (byte) 1, data);
		printData.add(content);
		reader.print(1, printData, 30, new PrintListener() {

			@Override
			public void onError(int errCode, String errDesc) {
				
			}

			@Override
			public void onPrintSucc() {
				
			}
		});
		return true;
	}
	
	@Override
	public boolean printBitMap(int position, Bitmap bitmap) {
		if (null == reader || null == bitmap) {
			return false;
		}
		ArrayList<MPosPrintLine> printData = new ArrayList<MPosPrintLine>();
		MPosPrintElecSignCache signV = new MPosPrintElecSignCache(AlignPosition.MID, (byte) 1, JBigUtil.JBIGCompressForPinter(BitmapUtil.getBitmap(bitmap, 320, 240)));
		printData.add(signV);
		reader.print(1, printData, 30, new PrintListener() {

			@Override
			public void onError(int errCode, String errDesc) {
				
			}

			@Override
			public void onPrintSucc() {
				
			}
		});
		return true;
	}

	@Override
	public boolean print(String data, Bitmap bitmap) {
		if (null == reader || null == data || null == bitmap) {
			return false;
		}
		ArrayList<MPosPrintLine> printData = new ArrayList<MPosPrintLine>();
		MPosPrintTextLine content = new MPosPrintTextLine(AlignPosition.LEFT, Font.ZOME2X2, (byte) 1, data);
		printData.add(content);
		MPosPrintElecSignCache signV = new MPosPrintElecSignCache(AlignPosition.MID, (byte) 1, JBigUtil.JBIGCompressForPinter(BitmapUtil.getBitmap(bitmap, 240, 100)));
		printData.add(signV);
		reader.print(1, printData, 30, new PrintListener() {

			@Override
			public void onError(int errCode, String errDesc) {
				
			}

			@Override
			public void onPrintSucc() {
				
			}
		});
		
		return true;
	}
	
	@Override
	public SwiperModel getSwiperModel() {
		return SwiperModel.M36_BLUETOOTH;
	}
}
